package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/path")
public class PathServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 1.转发
//            req.getRequestDispatcher("findAll").forward(req,resp);
        // 绝对路径:以/开头,表示的是应用名后面的/
//            req.getRequestDispatcher("/WEB-INF/test.jsp").forward(req,resp);
//            req.getRequestDispatcher("https://www.baidu.com/").forward(req,resp);
        // 2.重定向
        // 相对路径:不以/开头,相对于当前浏览器地址栏的路径
//            resp.sendRedirect("findAll");
        // 绝对路径:以/开头,表示的是端口号后面的/
//        resp.sendRedirect("/WEB-INF/test.jsp");
//        resp.sendRedirect("https://www.baidu.com/");
//        resp.sendRedirect("/web/findAll");
        // req.getContextPath():获取当前应用名
        resp.sendRedirect(req.getContextPath()+"/findAll");
    }
}
